//
//  AKuCaseManageCell.m
//  KMedicine
//
//  Created by 阿酷 on 16/7/7.
//  Copyright © 2016年 caomu. All rights reserved.
//

#import "AKuCaseManageCell.h"
#import "YYListModel.h"

@interface AKuCaseManageCell ()

// 小圆点
@property (nonatomic, weak) UIImageView *smallCircl;

// 时间
@property (nonatomic, weak) UILabel *commitTimeLabel;

// 疾病类型
@property (nonatomic, weak) UILabel *commonIllnessLabel;;

// 基本类型
@property (nonatomic, weak) UILabel *basisTypeLabel;;

// 描述
@property (nonatomic, weak) UILabel *describeLabel;


// 左边 图片
@property (nonatomic, weak) UIImageView *leftIMGView;


//不变的 文字   疾病类型
@property (nonatomic, weak) UILabel *commonLabel;

//不变的 文字   基本类型
@property (nonatomic, weak) UILabel *basisLabel;

@end

@implementation AKuCaseManageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        
        [self setupUI];
        
    }
    return self;
}


- (void)setupUI {
    
    // 时间
    self.commitTimeLabel = [self setLabelWithTextColor:[UIColor grayColor]];

    // 疾病类型
    self.commonIllnessLabel = [self setLabelWithTextColor:[UIColor grayColor]];
    
    // 基本类型
    self.basisTypeLabel = [self setLabelWithTextColor:[UIColor grayColor]];
    
    // 描述
    self.describeLabel = [self setLabelWithTextColor:[UIColor grayColor]];
    
    //不变的 文字   疾病类型
    self.basisLabel = [self setLabelWithTextColor:[UIColor blackColor]];
    self.basisLabel.text = @"基本类型:";
    [self.basisLabel sizeToFit];
    
    //不变的 文字   基本类型
    self.commonLabel = [self setLabelWithTextColor:[UIColor blackColor]];
    self.commonLabel.text = @"疾病类型:";
    [self.commonLabel sizeToFit];
    
    // 左边 图片
    UIImageView *leftIMGView = [[UIImageView alloc] init];
    
    self.leftIMGView = leftIMGView;
    
    leftIMGView.image = [UIImage imageNamed:@"illness_img_person.png"];
    
    [self.contentView addSubview:leftIMGView];
    
    // 小圆点
    UIImageView *smallCircl = [[UIImageView alloc] init];
    
    self.smallCircl = smallCircl;
    
    self.smallCircl.image = [UIImage imageNamed:@"illness_rb_img_sel.png"];
    [self.smallCircl sizeToFit];
    
    [self.contentView addSubview:smallCircl];
    
    
    //MARK: - 设置 约束
    [self setViewMasonry];
}

- (void)setViewMasonry {
    
    CGFloat margin = 10;
    
    // 小圆点
    [self.smallCircl mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.offset(margin);
        make.top.offset(margin);
        make.size.offset(self.smallCircl.bounds.size);
    }];
    
    
    // 时间
    [self.commitTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.smallCircl.top);
        make.left.equalTo(self.smallCircl.right).offset(margin);
        make.right.offset(-margin);
        make.height.offset(20);
    }];

  
    // 图片
    [self.leftIMGView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.commitTimeLabel.bottom).offset(6);
        make.left.equalTo(self.commitTimeLabel.left);
        make.height.equalTo(self).multipliedBy(0.6);
        make.width.equalTo(self.leftIMGView.height);
    }];
    
    //不变的 文字   疾病类型
    [self.commonLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.leftIMGView.right).offset(margin);
        make.size.offset(self.commonLabel.bounds.size);
        make.top.equalTo(self.commitTimeLabel.bottom).offset(6);
    }];
    
    
    //不变的 文字   基本类型
    [self.basisLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.leftIMGView.right).offset(margin);
        make.size.offset(self.basisLabel.bounds.size);
        make.top.equalTo(self.commonLabel.bottom).offset(6);
    }];
    
    // 疾病类型
    [self.commonIllnessLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.commonLabel.top);
        make.left.equalTo(self.commonLabel.right).offset(margin);
        make.right.offset(-10);
    }];

    
    // 基本类型
    [self.basisTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.equalTo(self.basisLabel);
        make.left.equalTo(self.basisLabel.right).offset(margin);
        make.right.offset(-10);
    }];
    
    
    
    
    // 描述
    [self.describeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.basisTypeLabel.bottom).offset(margin);
        make.bottom.equalTo(self.leftIMGView.bottom);
        make.left.equalTo(self.basisLabel.left);
        make.right.offset(-10);
    }];
    
    
    
    
    
    // 左边 中间 线条 view
    UIView *bolineView = [[UIView alloc] init];
    
    bolineView.backgroundColor = kThemeColor;
    
    [self.contentView addSubview:bolineView];
    
    
    [bolineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.smallCircl.centerX);
        make.top.equalTo(self.smallCircl.bottom);
        make.bottom.offset(0);
        make.width.offset(2);
    }];
    
    
    if ([self.reuseIdentifier isEqualToString:@"cell"]) {
        
        // 左边 上面 一点点  线条 view
        UIView *lineView = [[UIView alloc] init];
        
        lineView.backgroundColor = kThemeColor;
        
        [self.contentView addSubview:lineView];
        
        
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.centerX.equalTo(self.smallCircl.centerX);
            make.bottom.equalTo(self.smallCircl.top);
            make.top.offset(0);
            make.width.offset(2);
        }];
    }
}

- (void)setModeCell:(YYListModel *)modeCell {
    
    _modeCell = modeCell;
    
    self.commitTimeLabel.text    = modeCell.time;
    self.commonIllnessLabel.text = modeCell.illName;
    self.basisTypeLabel.text     = modeCell.illbase;
    self.describeLabel.text      = modeCell.illDetail;
    
    // 根据 图片的 地址 判断 是否 有图片
    if (modeCell.illImage) {
        
        self.leftIMGView.image = modeCell.illImage;
        
        //  移除 约束  从新设置 约束
        [self.leftIMGView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.commitTimeLabel.bottom).offset(6);
            make.left.equalTo(self.commitTimeLabel.left);
            make.height.equalTo(self).multipliedBy(0.6);
            make.width.equalTo(self.leftIMGView.height);
        }];
        
        
    } else {
        
        self.leftIMGView.image = modeCell.illImage;
        //  移除 约束  从新设置 约束

        [self.leftIMGView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.commitTimeLabel.bottom).offset(6);
            make.left.equalTo(self.commitTimeLabel.left);
            make.height.equalTo(self).multipliedBy(0.6);
            make.width.equalTo(20);
        }];
    }
}



#pragma mark - 设置 label
- (UILabel *)setLabelWithTextColor:(UIColor *)color {
    
    UILabel *label = [[UILabel alloc] init];
    
    label.textColor = color;
    label.textAlignment = NSTextAlignmentLeft;
    label.font = [UIFont systemFontOfSize:14];
    label.numberOfLines = 0;
    
    [self.contentView addSubview:label];

    return label;
}



@end













